<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>oa</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css"/>
</head>
<body>


<form class="layui-form" action="" style="margin-top: 20px;margin-right: 40px;">
    <div class="layui-form-item">
        <label class="layui-form-label">员工姓名</label>
        <div class="layui-input-block">
            <input type="text" name="empName" required  lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位</label>
        <div class="layui-input-block">
            <input type="text" name="title" required  lay-verify="required" placeholder="请输入职位" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <select name="dept" lay-verify="required">
                <option value=""></option>
                <option value="2">研发部</option>
                <option value="3">市场部</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职级</label>
        <div class="layui-input-inline">
            <input type="text" name="level" required lay-verify="required" placeholder="请输入职级" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">7为部门经理，7以下为普通员工</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入员工账号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" required  lay-verify="required" placeholder="请输入账号密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码盐值</label>
        <div class="layui-input-block">
            <input type="text" name="salt" required  lay-verify="required" placeholder="请输入密码盐值" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script src="/resources/layui/layui.js"></script>
<script src="/resources/sweetalert2.all.min.js"></script>
<script>
    var $ = layui.$; //jQuery对象
    layui.form.on('submit(sub)', function(data){
        console.info("向服务器提交的表单数据",data.field);
        $.post("/emp/add",data.field,function (json) {
            console.info(json);
            if(json.code == "0"){
                /*SweetAlert2确定对话框*/
                swal({
                    type: 'success',
                    html: "<h2>添加成功</h2>",
                    confirmButtonText: "确定"
                }).then(function (result) {
                    window.location.href="/forward/list";
                });
            }else{
                swal({
                    type: 'warning',
                    html: "<h2>" + json.message + "</h2>",
                    confirmButtonText: "确定"
                });
            }
        },"json");//告诉jquery 服务器返回的是json
        return false;
    });
</script>
</body>
</html>